﻿using System;
using System.Collections.Generic;
using System.Text;

namespace Titan.Configuration
{
    public class Config
    {
        static Config _instance;
        static object _lock = new object();
        readonly string _connectionString;
        readonly string _aDAccountCode;
        readonly string _aDLoginName;
        readonly string _aDPassword;
        readonly bool _aDLoginChecked;
        readonly string _schemaClass;

        private Config()
        {
            try
            {
                _connectionString = System.Configuration.ConfigurationManager.ConnectionStrings["AMS"].ToString();
                _aDAccountCode = System.Configuration.ConfigurationManager.AppSettings["ADAccountCode"].ToString();
                _aDLoginName = System.Configuration.ConfigurationManager.AppSettings["ADLoginName"].ToString();
                _aDPassword = System.Configuration.ConfigurationManager.AppSettings["ADPassword"].ToString();
                _aDLoginChecked = String.Compare(System.Configuration.ConfigurationManager.AppSettings["ADLoginChecked"].ToString(), "0", true) == 0?false:true;
                _schemaClass = System.Configuration.ConfigurationManager.AppSettings["SchemaClass"].ToString();

                LDAP = System.Configuration.ConfigurationManager.AppSettings["LDAPPath"].ToString();
            }
            catch(Exception er)
            {
                //throw new ConfigException("web.config", er);
            }
        }

        public string LDAP
        {
            get;
            private set;
        }

        static public Config Instance
        {
            get
            {
                if (null == _instance)
                {
                    lock (_lock)
                    {
                        if (null == _instance)
                            _instance = new Config();
                    }
                }
                return _instance;
            }
        }

        public string ConnectionString
        {
            get { return _connectionString; }
        }

        public string ADAccountCode
        {
            get{
                return _aDAccountCode;
            }
        }

        public string LoginName
        {
            get
            {
                return _aDLoginName;
            }
        }

        public string Password
        {
            get
            {
                return _aDPassword;
            }
        }

        public bool ADChecked
        {
            get
            {
                return _aDLoginChecked;
            }
        }

        public string SchemaClass
        {
            get
            {
                return _schemaClass;
            }
        }
    }
}
